package com.hunt.common.plugin;


import com.hunt.common.utils.AESUtil;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

/**
 * @program: hunt-lx
 * @description: 支持加密配置文件插件
 * @author: Lx
 * @create: 2019-01-31 17:52
 **/
public class EncryptPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer
{
    private String[] propertyNames = {"jdbc.password"};

    /**
     * 解密指定propertyName的加密属性值
     * @param propertyName
     * @param propertyValue
     * @return
     */
    @Override
    protected String convertProperty(String propertyName, String propertyValue)
    {
        for (String name : propertyNames)
        {
            if (name.equalsIgnoreCase(propertyName))
            {
                return AESUtil.aesDecode(propertyValue);
            }
        }
        return super.convertProperty(propertyName, propertyValue);
    }
}
